import com.sun.org.apache.xml.internal.security.c14n.helper.AttrCompare;

/**
 * @author : WXY
 * @create : 2022-08-19 21:13
 * @Info : 删除给定的值
 */
public class Code02_DeleteGivenValue {
    public static class Node{
        public int value;
        public Node next;

        public Node(int value) {
            this.value = value;
        }
    }

    public static Node removeValue(Node head, int num) {
        while (head != null) {
            if (head.value != num) {
                break;
            }
            head = head.next;
        }
        //此时，来到第一个不是num的位置
        Node pre = head;
        Node cur = head;
        while (cur != null) {
            if (cur.value == num) {
                pre.next = cur.next;
            }else {
                pre = cur;
            }
            cur = cur.next;
        }
        return head;
    }
}
